<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安全检查登记</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f5f7fa;
            margin: 0;
            padding: 0;
            color: #333;
            line-height: 1.6;
        }

        /* 导航栏样式 */
        .navbar {
            background-color: #ffffff;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 12px 0;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .navbar-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }

        .navbar-brand {
            font-size: 18px;
            font-weight: 600;
            color: #2c3e50;
            text-decoration: none;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 8px;
            color: #2980b9;
        }

        .navbar-nav {
            display: flex;
            align-items: center;
        }

        .nav-link {
            color: #555;
            font-size: 14px;
            text-decoration: none;
            font-weight: 500;
            margin-left: 15px;
            transition: color 0.3s ease;
            padding: 5px 10px;
            border-radius: 4px;
        }

        .nav-link:hover {
            color: #2980b9;
            background-color: #f0f8ff;
        }

        .btn-group {
            display: flex;
            align-items: center;
            margin-left: 15px;
        }

        .btn-group .btn {
            margin-left: 8px;
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 13px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            white-space: nowrap;
        }

        .btn-primary {
            background-color: #3498db;
            color: white;
            border: none;
        }

        .btn-primary:hover {
            background-color: #2980b9;
        }

        .btn-outline-primary {
            background-color: transparent;
            color: #3498db;
            border: 1px solid #3498db;
        }

        .btn-outline-primary:hover {
            background-color: #3498db;
            color: white;
        }

        .btn-success {
            background-color: #2ecc71;
            color: white;
            border: none;
        }

        .btn-success:hover {
            background-color: #27ae60;
        }

        .btn-warning {
            background-color: #f39c12;
            color: white;
            border: none;
        }

        .btn-warning:hover {
            background-color: #d35400;
        }

        .btn-info {
            background-color: #3498db;
            color: white;
            border: none;
        }

        .btn-info:hover {
            background-color: #2980b9;
        }

        .btn-danger {
            background-color: #e74c3c;
            color: white;
            border: none;
        }

        .btn-danger:hover {
            background-color: #c0392b;
        }

        .welcome-text {
            margin-left: 15px;
            font-size: 14px;
            color: #555;
        }

        /* 主容器样式 */
        .container {
            max-width: 1200px;
            margin: 30px auto;
            padding: 0 20px;
            display: flex;
            flex-wrap: nowrap;
            justify-content: space-between;
            align-items: flex-start;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background-color: #f9f9f9;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 20px;
            margin-right: 20px;
            position: static;
            float: none;
        }

        .sidebar-item {
            display: block;
            padding: 10px 15px;
            margin-bottom: 8px;
            background-color: white;
            border-radius: 5px;
            text-decoration: none;
            color: #555;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .sidebar-item:hover {
            background-color: #e8f5e9;
            color: #3a7d44;
        }

        /* 内容区域 */
        .content {
            flex: 1;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            padding: 25px;
            position: static;
            float: none;
        }

        h2 {
            color: #2c3e50;
            margin-bottom: 25px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        input[type="text"],
        input[type="number"],
        input[type="date"],
        select,
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            box-sizing: border-box;
        }

        .auto-fill {
            display: flex;
            align-items: center;
            margin-top: 5px;
        }

        .auto-fill input {
            margin-right: 5px;
        }

        .btn {
            padding: 10px 15px;
            border-radius: 4px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .btn-primary {
            background-color: #3498db;
            color: white;
            border: none;
        }

        .btn-primary:hover {
            background-color: #2980b9;
        }

        .btn-secondary {
            background-color: #6c757d;
            color: white;
            border: none;
        }

        .btn-secondary:hover {
            background-color: #5a6268;
        }

        .button-group {
            margin-top: 30px;
            display: flex;
            gap: 15px;
            justify-content: flex-end;
        }

        /* 检查项样式 */
        .check-item {
            margin-bottom: 20px;
            border-bottom: 1px solid #eee;
            padding-bottom: 15px;
        }

        .check-item:last-child {
            border-bottom: none;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                flex-direction: column;
            }

            .sidebar {
                margin-right: 0;
                margin-bottom: 20px;
            }
        }
    </style>
</head>
<body>

<!-- 导航栏 -->
<nav class="navbar">
    <div class="navbar-container">
        <a class="navbar-brand" href="#">
            <i class="fas fa-flask"></i>
            实验室辅助管理系统
        </a>
        <div class="navbar-nav">
            <span sec:authorize="isAuthenticated()">
                <div class="btn-group">
                    <a href="/laboratory/Info" class="btn btn-sm btn-outline-success active">实验室管理</a>
                    <a href="/email" class="btn btn-sm btn-outline-info">邮箱</a>
                    <a href="/user/admin" class="btn btn-sm btn-outline-warning">管理员界面</a>
                    <a href="/user/userInfo" class="btn btn-sm btn-outline-primary">个人中心</a>
                    <span class="welcome-text">欢迎, <span sec:authentication="name"></span>!</span>
                    <a href="/user/logout" class="btn btn-sm btn-outline-danger">退出</a>
                </div>
            </span>
        </div>
    </div>
</nav>

<!-- 主容器 -->
<div class="container">
    <!-- 侧边栏 -->
    <div class="sidebar">
        <ul>
            <li><a href="/item/list" class="sidebar-item">物品管理</a></li>
            <li><a href="/safety-inspection/list" class="sidebar-item">安全检查登记记录</a></li>
            <li><a href="/safety-inspection/" class="sidebar-item">今日安全检查登记</a></li>
        </ul>
    </div>

    <div class="content">
        <h2>安全检查登记</h2>

        <form id="safetyForm" th:action="@{/safety-inspection/add}" method="post" enctype="multipart/form-data">
            <!-- 实验室 -->
            <div class="form-group">
                <label for="laboratoryId">实验室 *</label>
                <select id="laboratoryId" name="laboratoryId" required>
                    <option value="">请选择实验室</option>
                    <option th:each="entry : ${labMap}" th:value="${entry.key}" th:text="${entry.value}"></option>
                </select>
            </div>

            <!-- 学期 -->
            <div class="form-group">
                <label for="termId">学期 *</label>
                <select id="termId" name="termId" required>
                    <option value="">请选择学期</option>
                    <option th:each="entry : ${termMap}" th:value="${entry.key}" th:text="${entry.value}"></option>
                </select>
            </div>

            <!-- 检查日期 -->
            <div class="form-group">
                <label for="inspectionDate">检查日期 *</label>
                <input type="date" id="inspectionDate" name="inspectionDate" required>
            </div>

            <!-- 检查项 -->
            <div class="form-group">
                <label>检查结果 *</label>
                <div>
                    <!-- 门窗检查 -->
                    <div class="check-item">
                        <label for="doorWindowCheck">门窗检查结果</label>
                        <textarea id="doorWindowCheck" name="doorWindowCheck" required></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="doorWindowCheck" data-content="门窗完好，无破损，锁具正常。">
                            <span>自动填写</span>
                        </div>
                    </div>

                    <!-- 电器线路检查 -->
                    <div class="check-item">
                        <label for="electricalCheck">电器线路检查结果</label>
                        <textarea id="electricalCheck" name="electricalCheck" required></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="electricalCheck" data-content="线路整齐无裸露，设备运行正常。">
                            <span>自动填写</span>
                        </div>
                    </div>

                    <!-- 消防设施检查 -->
                    <div class="check-item">
                        <label for="fireEquipmentCheck">消防设施检查结果</label>
                        <textarea id="fireEquipmentCheck" name="fireEquipmentCheck" required></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="fireEquipmentCheck" data-content="灭火器压力正常，消防通道畅通。">
                            <span>自动填写</span>
                        </div>
                    </div>

                    <!-- 仪器设备检查 -->
                    <div class="check-item">
                        <label for="instrumentCheck">仪器设备检查结果</label>
                        <textarea id="instrumentCheck" name="instrumentCheck" required></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="instrumentCheck" data-content="所有仪器设备状态良好，无异常。">
                            <span>自动填写</span>
                        </div>
                    </div>

                    <!-- 物品摆放检查 -->
                    <div class="check-item">
                        <label for="itemArrangementCheck">物品摆放检查结果</label>
                        <textarea id="itemArrangementCheck" name="itemArrangementCheck" required></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="itemArrangementCheck" data-content="物品摆放整齐，无安全隐患。">
                            <span>自动填写</span>
                        </div>
                    </div>

                    <!-- 清洁卫生检查 -->
                    <div class="check-item">
                        <label for="cleanlinessCheck">清洁卫生检查结果</label>
                        <textarea id="cleanlinessCheck" name="cleanlinessCheck" required></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="cleanlinessCheck" data-content="实验室整洁，无垃圾堆积。">
                            <span>自动填写</span>
                        </div>
                    </div>

                    <!-- 其他检查 -->
                    <div class="check-item">
                        <label for="otherCheck">其他检查结果</label>
                        <textarea id="otherCheck" name="otherCheck"></textarea>
                        <div class="auto-fill">
                            <input type="checkbox" data-target="otherCheck" data-content="无特殊问题，一切正常。">
                            <span>自动填写</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 整体状态 -->
            <div class="form-group">
                <label for="overallStatus">整体状态 *</label>
                <select id="overallStatus" name="overallStatus" required>
                    <option value="">请选择状态</option>
                    <option value="正常">正常</option>
                    <option value="异常上报">异常上报</option>
                </select>
            </div>

            <!-- 按钮组 -->
            <div class="button-group">
                <a href="/safety-inspection/list" class="btn btn-secondary">取消</a>
                <button type="submit" class="btn btn-primary">保存</button>
            </div>
        </form>
    </div>
</div>

<script>
    // 自动填充功能
    document.querySelectorAll('.auto-fill input').forEach(checkbox => {
        checkbox.addEventListener('change', function() {
            const targetId = this.getAttribute('data-target');
            const content = this.getAttribute('data-content');
            const textarea = document.getElementById(targetId);

            if (this.checked) {
                textarea.value = content;
            } else {
                textarea.value = '';
            }
        });
    });

    // 表单提交
    document.getElementById('safetyForm').addEventListener('submit', function(e) {
        e.preventDefault();
        const form = this;
        const formData = new FormData(form);

        fetch(form.getAttribute('action'), {
            method: 'POST',
            body: formData,
        })
            .then(response => {
                if (!response.ok) {
                    throw new Error('提交失败');
                }
                return response.json();
            })
            .then(data => {
                alert('提交成功');
                window.location.href = '/safety-inspection/list';
            })
            .catch(error => {
                alert('提交失败: ' + error.message);
            });
    });
</script>

</body>
</html>